import type { User } from '@/types';
import type { ImmerReducer } from 'umi';

export interface GlobalModelState {
  user: User | null;
}

export interface GlobalModelType {
  namespace: 'global';
  state: GlobalModelState;
  effects: {
    // fetch: Effect;
  };
  reducers: {
    setUser: ImmerReducer<GlobalModelState, { type: string; payload: GlobalModelState['user'] }>;
  };
}

const GlobalModel: GlobalModelType = {
  namespace: 'global',
  state: {
    user: null,
  },
  effects: {
    // *fetch(_, { call, put }) {
    // const response = yield call(queryGlobals);
    // yield put({
    //   type: 'save',
    //   payload: response,
    // });
    // },
  },
  reducers: {
    setUser(state: GlobalModelState, { payload }) {
      state.user = payload;
    },
  },
};

export default GlobalModel;
